#include "logicmodel.h"
#include<time.h>
#include<stdlib.h>

GameLogicModel::GameLogicModel()
    : mRow(kRow),
      mCol(kCol),
      totalMineCount(kMineCount),
      timerSeconds(kTime),
      gameState(In_progress)
{

}

GameLogicModel::~GameLogicModel()
{

}

void GameLogicModel::StartGame(int row, int col, int MineCount, GameLevel Level)
{
    Map.clear();

    mRow=row;
    mCol=col;
    totalMineCount=MineCount;
    CurMineCount=MineCount;
    gameState=In_progress;
    gameLevel=Level;
    timerSeconds=0;

    //初始化地图
    for(int i=0;i<mRow;i++)
    {
        std::vector<MineBlock> lineBlocks;
        for(int j=0;j<mCol;j++)
        {
            MineBlock mineBlock;
            mineBlock.CurState=Original;
            mineBlock.valueFlag=0;
            lineBlocks.push_back(mineBlock);
        }
        Map.push_back(lineBlocks);
    }

    //随机布雷
    srand((unsigned int)time(0));
    int k=totalMineCount;
    while(k>0)
    {
        int x=rand()%mRow;
        int y=rand()%mCol;
        if(Map[x][y].valueFlag!=-1)
        {
            Map[x][y].valueFlag=-1;
            k--;
        }
    }








}
